<template>
    <div id="userLayout" :class="['user-layout-wrapper']">
        <div class="container">
            <div class="hert" v-if="hasHertUrl"><img :src="loginBackGroupUrl" /></div>
            <div class="hert" v-else :style="{ backgroundImage: `url(${bgHert}) ` }"></div>
            <route-view ref="login" class="route"></route-view>
            <div class="footer">
                <div class="copyright">
                    {{ loginPageCopyright }}
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import RouteView from './RouteView'
import LoginApi from '@/api/login'
import { ParamsEncrypt } from '@lowcode/jpaas-common-lib'
import hert from '../image/hert.png'

export default {
    name: 'UserLayout',
    components: { RouteView },
    mixins: [ParamsEncrypt],
    data() {
        return {
            loginPageCopyright: '',
            bgHert: hert,
            sitettingJson: {},
            //是否有在线登录背景图
            hasHertUrl: false,
            //背景图片logo
            loginBackGroupUrl: '',
            //域名值
            hostName: '',
        }
    },
    created() {
        this.getTenantByUrl()
    },
    mounted() {
        document.body.classList.add('userLayout')
        this.getConfig()
    },
    methods: {
        getTenantByUrl() {
            this.hostName = window.location.hostname
        },
        getConfig() {
            var self = this
            LoginApi.getLoginConfig(this.hostName).then((res) => {
                let result = res.data
                if (result.sitettingJson) {
                    self.sitettingJson = JSON.parse(result.sitettingJson.confs)
                    if (self.sitettingJson.loginPageConfig) {
                        var loginPageConfig = self.sitettingJson.loginPageConfig
                        self.loginPageCopyright = self.$i18(loginPageConfig.loginPageCopyright)
                        if (loginPageConfig.loginBackGroup) {
                            self.hasHertUrl = true
                            self.loginBackGroupUrl = self.getFilePath(loginPageConfig.loginBackGroup)
                        }
                    }
                } else if (result.loginPageConfig) {
                    var loginPageConfig = JSON.parse(res.data.loginPageConfig)
                    self.loginPageCopyright = self.$i18(loginPageConfig.loginPageCopyright)
                }
            })
        },
        getFilePath(fileId) {
            return '/api/api-system/system/core/sysFile/public/download/' + fileId
        },
    },
    beforeDestroy() {
        document.body.classList.remove('userLayout')
    },
}
</script>

<style lang="less" scoped>
.hert {
    position: absolute;
    max-width: 43.2%;
    width: 100%;
    height: 0;
    padding-bottom: 36.54%;
    top: 50%;
    left: 10%;
    transform: translate(0, -50%);
    -webkit-transform: translate(0, -50%);
    -ms-transform: translate(0, -50%);
    -moz-transform: translate(0, -50%);
    z-index: 1;
    background-size: contain;
    img {
        max-width: 100%;
    }
}

.route {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 10%;
}

#userLayout.user-layout-wrapper {
    height: 100%;

    &.mobile {
        .container {
            .main {
                max-width: 368px;
                width: 98%;
            }
        }
    }

    .container {
        width: 100%;
        min-height: 100%;
        background: linear-gradient(to left bottom, #409eff, #99aefd);
        // background: #f0f2f5 url(~@/assets/background.svg) no-repeat 50%;
        background-size: 100%;
        /*padding: 110px 0 144px;*/
        position: relative;

        a {
            text-decoration: none;
        }

        .top {
            text-align: center;

            .header {
                height: 44px;
                line-height: 44px;

                .badge {
                    position: absolute;
                    display: inline-block;
                    line-height: 1;
                    vertical-align: middle;
                    margin-left: -12px;
                    margin-top: -10px;
                    opacity: 0.8;
                }

                .logo {
                    height: 44px;
                    vertical-align: top;
                    margin-right: 16px;
                    border-style: none;
                }

                .title {
                    font-size: 33px;
                    color: rgba(0, 0, 0, 0.85);
                    font-family: Avenir, 'Helvetica Neue', Arial, Helvetica, sans-serif;
                    font-weight: 600;
                    position: relative;
                    top: 2px;
                }
            }

            .desc {
                font-size: 14px;
                color: rgba(0, 0, 0, 0.45);
                margin-top: 12px;
                margin-bottom: 40px;
            }
        }

        .main {
            min-width: 260px;
            width: 368px;
            margin: 0 auto;
            z-index: 9;
        }

        .footer {
            position: absolute;
            width: 100%;
            bottom: 0;
            padding: 0 16px;
            margin: 48px 0 24px;
            text-align: center;

            .links {
                margin-bottom: 8px;
                font-size: 14px;

                a {
                    color: white;
                    transition: all 0.3s;

                    &:not(:last-child) {
                        margin-right: 40px;
                    }
                }
            }

            .copyright {
                color: white;
                font-size: 14px;
            }
        }
    }
}
</style>
